package com.dy.lock.screen.api.parse;

import java.util.Iterator;

import org.apache.log4j.Logger;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

import com.dy.lock.screen.api.vo.SmsVo;

public class ParseEmayInfo {

	private static Logger log = Logger.getLogger(ParseEmayInfo.class);

	@SuppressWarnings("unchecked")
	public static SmsVo parse(String xml) {
		SmsVo resInfo = null;
		Document document = null;
		Element root = null;
		// 读取XML文件,获得document对象
		try {
			document = DocumentHelper.parseText(xml);
			root = document.getRootElement();
			Iterator<Element> it = root.elementIterator();
			resInfo = new SmsVo();
			while (it.hasNext()) {
				Element secondEle = it.next();
				String tagName = secondEle.getName();
				if ("error".equalsIgnoreCase(tagName)) {
					resInfo.setError(secondEle.getTextTrim());
				} else if ("message".equalsIgnoreCase(tagName)) {
					resInfo.setMessage(secondEle.getTextTrim());
				}
			}
		} catch (DocumentException e) {
			log.error("解析亿美接口返回结果异常", e);
		}
		return resInfo;
	}

}
